package com.bauer.java.hadoop.mrduce.demo;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

/**
 * @program: java
 * @description: reduce
 * @author: bauer weo
 * @create: 2019-07-28 17:02
 */
public class WordCountReducer extends Reducer<Text, LongWritable, Text, LongWritable> {


    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        Iterator<LongWritable> count = values.iterator();
        Long sum = 0L;
        while (count.hasNext()) {
            sum = sum + count.next().get();
        }
        context.write(key, new LongWritable(sum));
    }
}
